
		Ext.onReady(function(){
			windowst.show();
			FenYe(0);
			
		});
		
		function FenYe(page){
			grids.getStore().removeAll();
			Ext.Ajax.request({
				url : "http://localhost:8080/querySalelyh",
				params :{page:page},
				method : "post",
				success : function(response) {

//					Ext.getCmp('salesName').setValue(orde[0].salesName);
//					Ext.getCmp('maker').setValue(orde[0].maker);
//					Ext.getCmp('departName').setValue(orde[0].departName);
//					Ext.getCmp('permitter').setValue(orde[0].permitter);
//					Ext.getCmp('projectName').setValue(orde[0].projectName);
					
					pageBean=Ext.JSON.decode(response.responseText,true);
					
					//alert(JSON.stringify(pageBean));
					var datas=pageBean.data;
					//alert(JSON.stringify(datas));
					pb=datas;
					
					forms.getForm().setValues(Ext.decode(response.responseText).data[0]);
					grids.getStore().add(Ext.decode(response.responseText).data[0].sales);
					
					forms.getForm.reset();
				},
			});
		}
		
		//保存
		function add(){
//			var grid =Ext.getCmp("girdss").getStore();
			var temp={
					customerID:Ext.getCmp('customerID').getValue(),
					billDate:Ext.getCmp('billDate').getValue(),
					addressID:Ext.getCmp('addressID').getValue(),
					billNo:Ext.getCmp('billNo').getValue(),
					billStyleID:Ext.getCmp('billStyleID').getValue(),
					custBillNo:Ext.getCmp('custBillNo').getValue(),
					isHanShui:Ext.getCmp('isHanShui').getValue(),
					custCyrrencyName:Ext.getCmp('custCyrrencyName').getValue(),
					billStatus:Ext.getCmp('billStatus').getValue(),
					exchRate:Ext.getCmp('exchRate').getValue(),
					salesName:Ext.getCmp('salesName').getValue(),
					maker:Ext.getCmp('maker').getValue(),
					departName:Ext.getCmp('departName').getValue(),
					permitter:Ext.getCmp('permitter').getValue(),
					projectName:Ext.getCmp('projectName').getValue(),
					isShenHe:Ext.getCmp('isShenHe').getValue(),
					isDel:Ext.getCmp('isDel').getValue(),
					sales:Ext.pluck(grids.getStore().data.items,"data"),
			};
			Ext.Ajax.request({
				url:'http://localhost:8080/insertSaleslyh',
				headers:{"Content-Type":"application/json"},
				params:JSON.stringify(temp),
				success:function(response){
					Ext.MessageBox.alert("提示","新增成功",function(){});
				}
			});
		}
		
		//获取页面上的值==》对历史交易查询新增
		function insertHistoryChecklyh(){
			
			var rowCount=grids.getStore().getCount();
			var prodIDs;
			var prdClassNames;
			var prodSizes;
			var sQuan;
			var sUnit;
			var oldPrice;
			var discounts;
			var sPrices;
			var amounts;
			var itemRemark;
			for (var i=0;i<rowCount;i++){
	        	 var data = grids.getStore().getAt(i).data;
	        	 prodIDs=data.prodID;
	        	 prdClassNames=data.prdClassName;
	        	 prodSizes=data.prodSize;
	        	 sQuan=data.sQuan;
	        	 sUnit=data.sUnit;
	        	 oldPrices=data.oldPrice;
	        	 discounts=data.discount;
	        	 sPrices=data.sPrice;
	        	 amounts=data.amount;
	        	 itemRemark=data.itemRemark;
//	        	 alert(prodIDs);
//	        	 alert(prdClassNames);
//	        	 alert(prodSizes);
//	        	 alert(sQuan);
//	        	 alert(sPrices);
	        }
			
			var temp={
					customerID:Ext.getCmp('customerID').getValue(),
					tranType:'销售订单',
					historyDate:Ext.getCmp('billDate').getValue(),
					fromNo:Ext.getCmp('billNo').getValue(),
					currID:Ext.getCmp('custCyrrencyName').getValue(),
					exchRate:Ext.getCmp('exchRate').getValue(),
					prodID:prodIDs,
					prdClassName:prdClassNames,
					prodSize:prodSizes,
					quantity:sQuan,
					unit:sUnit,
					oldPrice:oldPrices,
					discount:discounts,
					sPrice:sPrices,
					isTax:Ext.getCmp('isHanShui').getValue(),
					amount:amounts,
					remarks:itemRemark,
			};
			
			Ext.Ajax.request({
				url:'http://localhost:8080/insertHistoryChecklyh',
				headers:{"Content-Type":"application/json"},
				params:JSON.stringify(temp),
				success:function(response){
					Ext.MessageBox.alert("提示","新增成功",function(){});
				}
			});
		}
		
		//新增
		function XinZeng(){
			Ext.getCmp('customerID').setValue("");
			//Ext.getCmp('billDate').setValue("");
			Ext.getCmp('addressID').setValue("");
			Ext.getCmp('billNo').setValue("");
			Ext.getCmp('billStyleID').setValue("");
			Ext.getCmp('custBillNo').setValue("");
			Ext.getCmp('isHanShui').setValue("");
			Ext.getCmp('custCyrrencyName').setValue("");
			Ext.getCmp('billStatus').setValue("");
			Ext.getCmp('exchRate').setValue("");
			Ext.getCmp('salesName').setValue("");
			Ext.getCmp('maker').setValue("");
			Ext.getCmp('departName').setValue("");
			Ext.getCmp('permitter').setValue("");
			Ext.getCmp('projectName').setValue("");
			Ext.getCmp('isShenHe').setValue("");
			Ext.getCmp('isDel').setValue("");
			Ext.pluck(grids.getStore().removeAll());
		}
		
		function updatelyh(){
			//updateSaleslyh
			var temp={
					customerID:Ext.getCmp('customerID').getValue(),
					billDate:Ext.getCmp('billDate').getValue(),
					addressID:Ext.getCmp('addressID').getValue(),
					billNo:Ext.getCmp('billNo').getValue(),
					billStyleID:Ext.getCmp('billStyleID').getValue(),
					custBillNo:Ext.getCmp('custBillNo').getValue(),
					isHanShui:Ext.getCmp('isHanShui').getValue(),
					custCyrrencyName:Ext.getCmp('custCyrrencyName').getValue(),
					billStatus:Ext.getCmp('billStatus').getValue(),
					exchRate:Ext.getCmp('exchRate').getValue(),
					salesName:Ext.getCmp('salesName').getValue(),
					maker:Ext.getCmp('maker').getValue(),
					departName:Ext.getCmp('departName').getValue(),
					permitter:Ext.getCmp('permitter').getValue(),
					projectName:Ext.getCmp('projectName').getValue(),
					isShenHe:Ext.getCmp('isShenHe').getValue(),
					isDel:Ext.getCmp('isDel').getValue(),
					sales:Ext.pluck(grids.getStore().data.items,"data"),
			};
			Ext.Ajax.request({
				url:'http://localhost:8080/updateSaleslyh',
				headers:{"Content-Type":"application/json"},
				params:JSON.stringify(temp),
				success:function(response){
					Ext.MessageBox.alert("提示","删除成功",function(){});
					store.reload();
				}
			});
		}
		
		//审核
		function ShenHe(){
			var billNo = Ext.getCmp('billNo').getValue();
			
			Ext.Ajax.request({
				url:'http://localhost:8080/updateShenHelyh',
				params:{billNo:billNo,isShenHe:'已审核'},
				success:function(response){
					Ext.MessageBox.alert("提示","审核成功",function(){});
				}
			});
		}
		//反审核
		function FanShenHe(){
			var billNo = Ext.getCmp('billNo').getValue();
			
			Ext.Ajax.request({
				url:'http://localhost:8080/updateShenHelyh',
				params:{billNo:billNo,isShenHe:'未审核'},
				success:function(response){
					Ext.MessageBox.alert("提示","审核成功",function(){});
				}
			});
		}
		
		var toolbar=Ext.create('Ext.toolbar.Toolbar',{
    		renderTo:document.body,
    		width:608,
    		items:[
    		       {text:'上一页',handler:function(){FenYe(pageBean.prevPage);}},
    		       {text:'下一页',handler:function(){FenYe(pageBean.nextPage);}},
    		       {text:'保存',handler:function(){add(); insertHistoryChecklyh();}},
    		       {text:'新增',handler:function(){XinZeng();}},
    		       {text:'修改'},
    		       {text:'删除',handler:function(){updatelyh();}},
    		       {text:'刷新',handler:function(){}},
    		       {xtype:'tbspacer',width:190},
    		       {text:'审核',handler:function(){ShenHe();}},
    		       {text:'反审核',handler:function(){FanShenHe();}}
    		       ],
    	});
		
		var fielmenu=new Ext.menu.Menu({
			items:[{text:'历史交易查询',handler:function(){afronction();}}]
		});
		
		var fielmenu1=new Ext.menu.Menu({
			items:[{text:'转销售出库单'},{text:'销售报价单转入',handler:function(){baojia();}}]
		});
		
		var fielmenu2=new Ext.menu.Menu({
			items:[{text:'批次变更单价'},{text:'物料组合设定'},{text:'单况状态切换'}]
		});
		
		var grids=Ext.create('Ext.grid.Panel',{
			listeners:{
				containerdblclick:function(gridc,e,eOpts){
					gridc.getStore().add({
						'rownumberer':'','prodID':'','prdClassName':'',
						'prodSize':'','sUnit':'','sQuan':'','oldPrice':'',
						'discount':'','sPrice':'','amount':'','taxRate':'',
						'taxAmt':'','vFTotal':'','preInDate':'','qtyRemain':'',
						'isGift':'','itemRemark':'','hasCombine':'','tranType':'',
						'fromNo':'','isManu':'','arrangeNo':'','manuQty':''
					});
				}
			},
			plugins:[
			        Ext.create('Ext.grid.plugin.CellEditing',{
			        	clicksToEdit:1
			        }) 
			        ],
			columns:[
				{header:'(栏号)',xtype:'rownumberer',dataIndex:'lh',width:50,sortable:false},
				{header:'物料编号',dataIndex:'prodID',width:100,editor:"textfield"},
				{header:'物料名称',dataIndex:'prdClassName',width:120,editor:"textfield"},
				{ header: '规格型号', dataIndex: 'prodSize' ,editor:"textfield"},
				{ header: '单位名称', dataIndex: 'sUnit',editor:"textfield"},
				{ header: '数量', dataIndex: 'sQuan',editor:"textfield"},
				{ header: '折扣前单价', dataIndex: 'oldPrice',editor:"textfield"},
				{ header: '折数(%)', dataIndex: 'discount',editor:"textfield"},
				{ header: '单价', dataIndex: 'sPrice',editor:"textfield"},
				{ header: '金额', dataIndex: 'amount',editor:"textfield"},
				{ header: '税率', dataIndex: 'taxRate',editor:"textfield"},
				{ header: '税额', dataIndex: 'taxAmt',editor:"textfield"},
				{ header: '含税金额', dataIndex: 'vFTotal',editor:"textfield"},
				{ header: '预出库日',dataIndex: 'preInDate',format:'Y-m-d',editor:"datefield"},
				{ header: '未出数量', dataIndex: 'qtyRemain',editor:"textfield"},
				{ header: '赠品', dataIndex: 'isGift',editor:"textfield"},
				{ header: '分录备注', dataIndex: 'itemRemark',editor:"textfield"},
				{ header: '物料组合', dataIndex: 'hasCombine',editor:"textfield"},
				{ header: '来源单别', dataIndex: 'tranType',editor:"textfield"},
				{ header: '来源单号', dataIndex: 'fromNo',editor:"textfield"},
				{ header: '生产', dataIndex: 'isManu',editor:"textfield"},
				{ header: '排程单号', dataIndex: 'arrangeNo',editor:"textfield"},
				{ header: '已生产数量', dataIndex: 'manuQty',editor:"textfield"}
			],
			height:130,
			width:1971,
			autoScroll:false,
		});
		
		
		var filterPanel = Ext.create('Ext.panel.Panel',{
			bodyPadding:6,
			width:1985,
			height:170,
			items:[grids],
			bbar:[{xtype:"label",text:'总计',width:90},
			{xtype:"textfield",disabled:true,width:90,margin:'0 180',value:'0.00'},
			{xtype:"textfield",disabled:true,width:90,margin:'0',value:'0.00'},
			{xtype:"textfield",disabled:true,width:90,margin:'0 40 0 30',value:'0.00'},
			{xtype:"textfield",disabled:true,width:90,margin:'0 0 0 0',value:'0.00'}],
		});
		
		var ZKPanel =Ext.create('Ext.form.Panel',{
			bodyPadding: 5,
			height:'100%',
			layout:"column",
			baseCls:'x-plain',
			items:[{
				xtype: 'textfield',
		        name: 'zkgs',
				bodyPadding: 5,
		        fieldLabel: '帐款归属',
				width:250,
		        labelWidth: 80,
		        anchor: '100%',
				},{
				xtype: 'datefield',
		        name: 'zkrq',
		        fieldLabel: '帐款日期',
				style:'margin-left:19px',
				width:250,
				format:'Y-m-d',
		        altFormats:'Y/m/d|Ymd',
		        labelWidth: 80,
		        anchor: '100%',
				},{
				xtype: 'combo',
		        name: 'sktj',
		        fieldLabel: '收款条件',
				width:150,
		        labelWidth: 80,
		        valueField:'abbr',
		        displayField:'name',
		        store:Ext.create('Ext.data.Store',{
		        	fields: ['abbr', 'name'],
    				data : [
        				{"abbr":"货到", "name":"货到"},
        				{"abbr":"次月", "name":"次月"},
        				{"abbr":"月结", "name":"月结"},
        				{"abbr":"其他", "name":"其他"}
					]
		        }),
		        value:'货到',
		        typeAhead:true,
		        mode:'local',
		        triggerAction:'all',
		        selectOnFocus:true,
				},{
				xtype: 'textfield',
		        name: 'sktjj',
				width:99,
		        labelWidth: 70,
				margin:"0 1",
		        anchor: '100%',
				},{
				xtype: 'datefield',
		        name: 'zkyf',
		        fieldLabel: '帐款月份',
				style:'margin-left:19px',
				width:250,
		        labelWidth: 80,
		        anchor: '100%',
				}],
		});
		
		//中间
		var tableds=Ext.create('Ext.TabPanel',{
			width:"100%",
			height:230,
			autoScroll:true,
			bodyPadding:5,
			items:[{title:'内容',autoScroll:true,items:[filterPanel]},{title:'帐款',autoScroll:true,items:[ZKPanel]},{title:'备注',xtype:'textarea',name:'Remark',fieldLabel: '备注',labelWidth: 30,}],
		});
		
		
		//尾部
		var formsg=Ext.create('Ext.form.Panel', {
	    bodyPadding: 5,
		height:'100%',
		layout:"column",
		baseCls:'x-plain',
		items:[{
			xtype: 'textfield',
	        name: 'salesName',
	        id:'salesName',
			style:'margin-left:20px',
	        fieldLabel: '业务人员',
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
			},{
			xtype: 'textfield',
	        name: 'maker',
	        id:'maker',
	        fieldLabel: '制单人员',
			style:'margin-left:20px',
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
			},{
			style:'margin-left:20px',
			xtype: 'textfield',
	        name: 'departName',
	        id:'departName',
	        fieldLabel: '所属部门',
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
			},{
			style:'margin-left:20px',
			xtype: 'textfield',
	        name: 'permitter',
	        id:'permitter',
	        fieldLabel: '复核人员',
			style:'margin-left:19px',
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
			},{
			style:'margin-left:20px',
			xtype: 'textfield',
	        name: 'projectName',
	        id:'projectName',
	        fieldLabel: '所属项目',
			width:250,
	        labelWidth: 80,
	        anchor: '100%',
			}],
		});
		
		
		//头部form表单
		var forms=Ext.create('Ext.form.Panel', {
    	bodyPadding: 5,
		height:'100%',
		layout:"column",
		baseCls:'x-plain',
		items:[
		{
		style:'margin-left:20px;',
		xtype: 'textfield',
        name: 'customerID',
        fieldLabel: '客户',
		width:250,
        labelWidth: 80,
		emptyText:'请输入客户',
        anchor: '100%',
        id:'customerID',
		},{
		style:'margin-left:30px;color:blue',
		xtype: 'datefield',
        name: 'billDate',
        fieldLabel: '单据日期',
		width:250,
		format:'Y-m-d',
        altFormats:'Y/m/d|Ymd',
        labelWidth: 70,
        anchor: '100%',
        id:'billDate',
		},{
		style:'margin-left:20px;',
		xtype: 'textfield',
        name: 'addressID',
        fieldLabel: '送货地址',
		width:150,
        labelWidth: 80,
        anchor: '100%',
        id:'addressID',
		},{
		xtype: 'textfield',
        name: 'dizhiton',
		width:99,
        labelWidth: 70,
		margin:"0 1",
        anchor: '100%',
		},{
		style:'margin-left:30px;color:blue',
		xtype:'textfield',
		name:'billNo',
		fieldLabel:'单据号码',
		width:250,
		labelWidth:70,
		anchor:'100%',
		id:'billNo',
		},{
		style:'margin-left:20px;',
		xtype:'textfield',
		name:'billStyleID',
		fieldLabel:'销售订单类型',
		labelWidth:80,
		width:250,
		anchor:'100%',
		id:'billStyleID',
		},{
		style:'margin-left:30px;',
		xtype:'textfield',
		name:'custBillNo',
		fieldLabel:'客户订单',
		width:250,
		labelWidth:70,
		anchor:'100%',
		id:'custBillNo',
		},{
		style:'margin-left:20px;',
		fieldLabel:'单价是否含税',
		xtype:'combo',
		name:'isHanShui',
		displayField:'s',
		labelWidth:80,
		width:250,
		id:'isHanShui',
		valueField:'a',
		store:Ext.create('Ext.data.Store',{
			fields:['a','s'],
			data:[
				{"a":"含税","s":"含税"},
				{"a":"未税","s":"未税"}
			]
		}),
		value:'含税',
		typeAhead:true,
		mode:'local',
		triggerAction:'all',
		selectOnFocus:true,
		},{
		xtype:'textfield',
		fieldLabel:'币别',
		style:'margin-left:30px;',
		width:250,
		labelWidth:70,
		anchor:'100%',
		name:'custCyrrencyName',
		id:'custCyrrencyName',
		},{
		style:'margin-left:20px;',
		name:'billStatus',
		id:'billStatus',
		fieldLabel:'单况',
		xtype:'combo',
		displayField:'name',
		labelWidth:80,
		width:250,
		valueField:'abbr',
		store:Ext.create('Ext.data.Store',{
			fields:['abbr','name'],
			data:[
				{"abbr":"未结案","name":"未结案"},
				{"abbr":"已结案","name":"已结案"},
				{"abbr":"无效","name":"无效"}
			]
		}),
		value:'未结案',
		typeAhead:true,
		mode:'local',
		triggerAction:'all',
		selectOnFocus:true,
		},{
		style:'margin-left:30px;',
		xtype:'textfield',
		name:'exchRate',
		id:'exchRate',
		fieldLabel:'汇率',
		labelWidth:70,
		width:250,
		anchor:'100%',
		},{
		xtype:'textfield',
		name:'isDel',
		fieldLabel:'是否删除',
		hidden: true, 
		hideLabel:true,
		id:'isDel',
		},{
		xtype:'textfield',
		name:'isShenHe',
		fieldLabel:'是否审核',
		hidden: true, 
		hideLabel:true,
		id:'isShenHe',
		},tableds,formsg]
    });
		
		
		//窗体大小
		var windowst=new Ext.Window({
			width:620,
			height:540,
			title:"销售订单",
			closable:true,
			resizable:false, //设置是否可以改变大小
			draggable:true,
			anchor: '100%',
 			items:[toolbar,forms],
 			bbar:[{xtype:'splitbutton',text:'查询',width:90,menu:fielmenu},
 			{xtype:'splitbutton',text:'转单',width:90,menu:fielmenu1},
 			{xtype:'splitbutton',text:'功能',width:90,menu:fielmenu2}],
		});
		
		function afronction(){
			var customerID=Ext.getCmp('customerID').getValue();
			Ext.Ajax.request({
				url:'http://localhost:8080/queryhissalesVolyh',
				params:{customerID:customerID},
				success:function(response){
					if(response.responseText==""){
						Ext.MessageBox.alert("提示","没有查询到!!!",function(){});
					}else{
					Ext.MessageBox.alert("提示","查询成功!!!",function(){});
					gridss.getStore().add(Ext.decode(response.responseText));
					}
				}
			});
//			var song = Ext.encode(forms.getForm().getValues());
			windowstz.show();
		}
		
		function baojia(){
			windowsts.show();
		}
		
